package net.lab1024.sa.admin.module.business.devicesAlarmList.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.devicesAlarmList.dao.DevicesAlarmListDao;
import net.lab1024.sa.admin.module.business.devicesAlarmList.domain.entity.DevicesAlarmListEntity;
import net.lab1024.sa.admin.module.business.devicesAlarmList.domain.form.DevicesAlarmListAddForm;
import net.lab1024.sa.admin.module.business.devicesAlarmList.domain.form.DevicesAlarmListQueryForm;
import net.lab1024.sa.admin.module.business.devicesAlarmList.domain.form.DevicesAlarmListUpdateForm;
import net.lab1024.sa.admin.module.business.devicesAlarmList.domain.vo.DevicesAlarmListVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 实时告警列表 Service
 *
 * @Author 1
 * @Date 2025-07-14 09:31:27
 * @Copyright 1
 */

@Service
public class DevicesAlarmListService {

    @Resource
    private DevicesAlarmListDao devicesAlarmListDao;

    /**
     * 分页查询
     */
    public PageResult<DevicesAlarmListVO> queryPage(DevicesAlarmListQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<DevicesAlarmListVO> list = devicesAlarmListDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(DevicesAlarmListAddForm addForm) {
        DevicesAlarmListEntity devicesAlarmListEntity = SmartBeanUtil.copy(addForm, DevicesAlarmListEntity.class);
        devicesAlarmListDao.insert(devicesAlarmListEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(DevicesAlarmListUpdateForm updateForm) {
        DevicesAlarmListEntity devicesAlarmListEntity = SmartBeanUtil.copy(updateForm, DevicesAlarmListEntity.class);
        devicesAlarmListDao.updateById(devicesAlarmListEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        devicesAlarmListDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        devicesAlarmListDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
